package com.safe.first.infrastructure.service;

import com.safe.first.domain.user.DefaultUser;
import com.safe.first.domain.user.User;
import com.safe.first.domain.user.repo.UserRepo;
import lombok.AllArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author Mickey
 * @since 2022/6/26
 **/
@Service
@AllArgsConstructor
public class VerificationCodeUserDetailsService implements UserDetailsService {

    private final UserRepo userRepo;

    @Override
    public UserDetails loadUserByUsername(String mobile) throws UsernameNotFoundException {
        User user = userRepo.byMobile(mobile);
        return (DefaultUser) user;
    }
}
